using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PACKETPARSERMAX20.CORE;

namespace PACKETPARSERMAX20.CORE.DEFINITIONS
{
    public class SMSG_ATTACKERSTATEUPDATE_DEF : DefinitionBase
    {

        public override bool Process()
        {
            ResetPosition();

            HitInfo hitInfo = (HitInfo)ReadUInt32();
            UInt64 attacker = popGuid();
            UInt64 target = popGuid();
            UInt32 fulldamage = ReadUInt32();                     // Full damage
            UInt32 overkill = ReadUInt32();                                      // overkill value
            byte count = ReadByte();                                   // Sub damage count

           // InitLog(); //start the log
          //  if(LogIt) LogAppendLine("UInt32", "hitInfo", (uint)hitInfo, "", hitInfo.DumpFlags());
          //  if(LogIt) LogAppendLine("UInt64", "attacker", attacker, true);
          //  if(LogIt) LogAppendLine("UInt64", "target", target, true);
          //  if(LogIt) LogAppendLine("UInt32", "fulldamage", fulldamage);
          //  if(LogIt) LogAppendLine("UInt32", "overkill", overkill);
          //  if(LogIt) LogAppendLine("byte", "count", count);

            for (int i = 0; i < count; ++i)
            {
                UInt32 damageSchoolMask = ReadUInt32();       // School of sub damage
                float damage1 = ReadSingle();                 // sub damage
                UInt32 damage2 = ReadUInt32();                 // Sub Damage

              //  if(LogIt) LogAppendLine("UInt32", "damageSchoolMask", damageSchoolMask, i);
              //  if(LogIt) LogAppendLine("float", "damage1", damage1, i);
              //  if(LogIt) LogAppendLine("UInt32", "damage2", damage2, i);
            }

            if ((hitInfo & (HitInfo.HITINFO_ABSORB | HitInfo.HITINFO_ABSORB2)) > 0)
            {

                for (int i = 0; i < count; ++i)
                {
                    UInt32 absorb = ReadUInt32();            // Absorb
                  //  if(LogIt) LogAppendLine("UInt32", "absorb", absorb, i, "HITINFO_ABSORB | HITINFO_ABSORB2");
                }
            }

            if ((hitInfo & (HitInfo.HITINFO_RESIST | HitInfo.HITINFO_RESIST2)) > 0)
            {
                for (int i = 0; i < count; ++i)
                {
                    UInt32 resist = ReadUInt32();            // Resist
                  //  if(LogIt) LogAppendLine("UInt32", "resist", resist, i, "HITINFO_RESIST | HITINFO_RESIST2");
                }
            }

            byte TargetState = ReadByte();
            UInt32 unk1 = ReadUInt32();
            UInt32 unk2 = ReadUInt32();

          //  if(LogIt) LogAppendLine("byte", "TargetState", TargetState);
          //  if(LogIt) LogAppendLine("UInt32", "unk1", unk1);
          //  if(LogIt) LogAppendLine("UInt32", "unk2", unk2);

            if ((hitInfo & HitInfo.HITINFO_BLOCK) > 0)
            {
                UInt32 BlockedAmount = ReadUInt32();
              //  if(LogIt) LogAppendLine("UInt32", "BlockedAmount", BlockedAmount, "HITINFO_BLOCK");
            }

            if ((hitInfo & HitInfo.HITINFO_UNK3) > 0)
            {
                UInt32 unk3 = ReadUInt32();
              //  if(LogIt) LogAppendLine("UInt32", "unk3", unk3, "HITINFO_UNK3");
            }

            if ((hitInfo & HitInfo.HITINFO_UNK1) > 0)
            {
                UInt32 unk4 = ReadUInt32();
                float float_0 = ReadSingle();
                float float_1 = ReadSingle();
                float float_2 = ReadSingle();
                float float_3 = ReadSingle();
                float float_4 = ReadSingle();
                float float_5 = ReadSingle();
                float float_6 = ReadSingle();
                float float_7 = ReadSingle();

              //  if(LogIt) LogAppendLine("UInt32", "unk4", unk4, "HITINFO_UNK1");
              //  if(LogIt) LogAppendLine("float", "float_0", float_0, "HITINFO_UNK1");
              //  if(LogIt) LogAppendLine("float", "float_1", float_1, "HITINFO_UNK1");
              //  if(LogIt) LogAppendLine("float", "float_2", float_2, "HITINFO_UNK1");
              //  if(LogIt) LogAppendLine("float", "float_3", float_3, "HITINFO_UNK1");
              //  if(LogIt) LogAppendLine("float", "float_4", float_4, "HITINFO_UNK1");
              //  if(LogIt) LogAppendLine("float", "float_5", float_5, "HITINFO_UNK1");
              //  if(LogIt) LogAppendLine("float", "float_6", float_6, "HITINFO_UNK1");
              //  if(LogIt) LogAppendLine("float", "float_7", float_7, "HITINFO_UNK1");

                for (int i = 0; i < 5; ++i)
                {
                    float float_8 = ReadSingle();
                    float float_9 = ReadSingle();

                  //  if(LogIt) LogAppendLine("float", "float", float_8, i, "HITINFO_UNK1");
                  //  if(LogIt) LogAppendLine("float", "float", float_9, i, "HITINFO_UNK1");
                }
                UInt32 unk5 = ReadUInt32();
              //  if(LogIt) LogAppendLine("UInt32", "unk5", unk5, "HITINFO_UNK1");
            }

            //UInt32 hitInfo = ReadUInt32();
            //ulong guid = popGuid();
            //ulong targetGUID = popGuid();
            //UInt32 stats = ReadUInt32();
            //if (ClientBuild >= 9183)
            //{
            //    UInt32 overkill = ReadUInt32();
            //}

            //byte SwingType = ReadByte();                               // count?

            //UInt32 damageSchoolMask = ReadUInt32();
            //float stats2 = ReadSingle();
            //UInt32 stats3 = ReadUInt32();


            //if ((hitInfo & ((uint)HitInfo.HITINFO_ABSORB | (uint)HitInfo.HITINFO_ABSORB2)) > 0)
            //{
            //    UInt32 AbsorbDamage = ReadUInt32();
            //}

            //if ((hitInfo & ((uint)HitInfo.HITINFO_RESIST | (uint)HitInfo.HITINFO_RESIST2)) > 0)
            //{
            //    UInt32 Resist = ReadUInt32();
            //}

            ////HITINFO_NORMALSWING2 True
            ////1024 True
            ////2048 True
            ////4096 True

            //if ((hitInfo & ((uint)HitInfo.HITINFO_NORMALSWING2 | (uint)HitInfo.HITINFO_MISS)) > 0)
            //{
            //    UInt32 TargetState = ReadUInt32();
            //    UInt32 unk1 = ReadUInt32();
            //    byte unk2 = ReadByte();
            //}
            //else
            //{
            //    UInt32 TargetState = ReadUInt32();
            //    UInt32 unk1 = ReadUInt32();
            //    UInt32 unk2 = ReadUInt32();
            //}

            //if ((hitInfo & (uint)HitInfo.HITINFO_BLOCK) > 0)
            //{
            //    UInt32 BlockedAmount = ReadUInt32();
            //}

            //if ((hitInfo & (uint)HitInfo.HITINFO_UNK3) > 0)
            //{
            //    UInt32 unk3 = ReadUInt32();
            //}

            //if ((hitInfo & (uint)HitInfo.HITINFO_UNK1) > 0)
            //{
            //    UInt32 unk4 = ReadUInt32();
            //    float float_0 = ReadSingle();
            //    float float_1 = ReadSingle();
            //    float float_2 = ReadSingle();
            //    float float_3 = ReadSingle();
            //    float float_4 = ReadSingle();
            //    float float_5 = ReadSingle();
            //    float float_6 = ReadSingle();
            //    float float_7 = ReadSingle();
            //    for (int i = 0; i < 5; ++i)
            //    {
            //        float float_8 = ReadSingle();
            //        float float_9 = ReadSingle();
            //    }
            //    UInt32 unk5 = ReadUInt32();
            //}
 
            return Validate();
        }
    }
}

